<!--
 * @Description: 
 * @Author: Haor
 * @Date: 2022-01-14 15:42:32
 * @LastEditTime: 2022-01-24 14:17:01
 * @LastEditors: Haor
-->
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./src/Tree.js"></script>
</head>
<body>
    <script>
        const treeList = [{
            id: '1',
            parentId: 0,
            name: '四川省',
            children: [
                {
                    id: '1-1',
                    parentId: '1',
                    name: '成都市',
                    children: [
                        {
                            id: '1-1-1',
                            parentId: '1-1',
                            name: '武侯区'
                        },
                        {
                            id: '1-1-2',
                            parentId: '1-1',
                            name: '金牛区'
                        },
                    ]
                },
                {
                    id: '1-2',
                    parentId: '1',
                    name: '绵阳市'
                },
                {
                    id: '1-3',
                    parentId: '1',
                    name: '德阳市'
                }
            ]
        }]


        const treeObj = new Tree(treeList, {
            id: 'id',
            parentId: 'parentId',
            children: 'children',
            name: 'name'
        })

    
        //--------------------------------------------------------
        
        // 获取（武侯区）的上上级别
        const parents = treeObj.getParentsById('1-1-1', (item) => {
            console.log('item>>>:', item)
            return item.name
        })
        console.log(parents.join('/'))
    
        //--------------------------------------------------------

        // 获取指定的子集
        const chidlren = treeObj.getChildrenById('1-1')
        console.log('chidlren>>>:', chidlren)
        
        //--------------------------------------------------------

        // 通过id获取名称
        const names = treeObj.getNameByIdList('1-1-2', '1-3', '1-2')
        console.log('names>>>:', names)

        //--------------------------------------------------------
        

        // 通过id获取孩子数量
        const childSize = treeObj.getChildSize('1-1')
        console.log('childSize>>>:', childSize)
    </script>
</body>
</html>